

public class MyblockingQueue {
    private int[] elem = new int[10];
    private volatile int size = 0;
    private volatile int head = 0;
    private volatile int tail = 0;
    public void put(int val) throws InterruptedException {
        synchronized (this){
            while(elem.length==size){
                //阻塞等待
                this.wait();
            }
            elem[tail] = val;
            size++;
            tail= (tail+1)%elem.length;
            this.notifyAll();
        }
    }
    public int take(int val) throws InterruptedException {
        int a= 0;
            synchronized (this){
                while(size==0){
                    //阻塞等待
                    this.wait();
                }
                a = elem[head];
                head= (head+1)% elem.length;
                size--;
                this.notifyAll();
            }
            return a;
    }
    public synchronized int size(){
        return size;
    }

}
